import pandas as pd
def csv_to_txt(i_path,o_path,cul_list):
    """
    csv转化为def,指定开始列结束列
    :param i_path: 输入文件路径
    :param o_path: 输出文件路径
    :param cul_list: 需要的列列表
    :return: 无
    """
    df = pd.read_csv(i_path)
    df_cul = df.columns
    with open(o_path,'w') as f:
        for _, cul in df.iterrows():
            a_str = ""
            q_str = ""
            for i in cul_list:
                if i != cul_list[-1]:
                    a_str += str(df_cul[i - 1]) + ":" + str(cul[i-1])+","
                else:
                    q_str = str(cul[i-1])
            str_list = list(q_str)
            str_list[0] = ""
            q_str = ''.join(str_list)
            qa_str = q_str+"\t"+a_str+"\n"
            f.write(qa_str)
if __name__ == '__main__':
    csv_to_txt(r'C:\Users\Lenovo\Desktop\challenge_cup\bert\BERT_PET\PET\data\pre_linux\Linux_2k.log_templates.csv',r"C:\Users\Lenovo\Desktop\challenge_cup\bert\BERT_PET\PET\data\processed_linux\Linux_2k.log_templates.txt",[2,1])